package view.equipe;

import java.awt.Color;
import java.awt.Dimension;
import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BorderFactory;
import javax.swing.JLabel;

import rmi.RemoteObserver;
import rmi.UtilitairesRmi;
import server.models.tireur.ITireur;


public class TireurView extends JLabel implements RemoteObserver {

	private static final long serialVersionUID = 1L;
	
	private ITireur tireurObserver = null; 

	public TireurView(ITireur tireur) throws RemoteException {
		super(tireur.getSurnom());
		tireurObserver = tireur;
		try {
			tireur.addObserver((RemoteObserver)UtilitairesRmi.getInstance().obtenirEtBind(this.getClass().getName() + "_" + tireur.getSurnom(), this));
		} catch (NotBoundException | AlreadyBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
		initialiseGraphic();
		this.setText(tireur.getParticipant().getSurnom());
	}

	private void initialiseGraphic() {
		this.setPreferredSize(new Dimension(100, 100));
		this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.setVerticalAlignment(CENTER);
		this.setHorizontalAlignment(CENTER);
		this.repaint();
		this.setVisible(true);
	}
	
	@Override
	public void update(Object tireur, Object arg1) {
		try {
			this.setText(((ITireur)tireur).getSurnom());
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		this.repaint();
	}
}
